Postgres relation does not exist when adding column to table? - node.js

I'm trying to create a schema and add tables to it via node using node-postgres (pg). The basic order of events is as follows:
1. Create schema
2. Create table in schema
3. Create columns in table in schema
I can verify that the schema and the table are being created without issues, but I get a relation does not exist error when trying to add the first column to the table. The query string for creating the column looks like this:
"ALTER TABLE " +
schemaName +
".process ADD COLUMN process_id bigint NOT NULL DEFAULT nextval('" +
schemaName +
".process_process_id_seq'::regclass)";
I've confirmed in the console log that the schema name variable matches what is was used to successfully create the table. Any ideas on why the error is being thrown here?

The sequence needs to be created beforehand.
But you could also use the bigserial type which is a shortcut for a bigint column with a sequence and a respective DEFAULT created automatically. Something along the lines of:
"ALTER TABLE " +
schemaName +
".process ADD COLUMN process_id bigserial";
Maybe you fell over that. Later, when the table/column was created you cannot see the ...serial anymore but the actual type and the DEFAULT.
More on ...serial types can be found in the documentation.

Related

<Today_date>T00:00:00.000+0000 is not returned when TODAY is used in Where clause

I am inserting record with scan_date as <Today_date>T00:00:00.000+0000, but I am not able retrieve the same using scan_date = TODAY (SOQL).
example:
There is record with scan_date = "2022-01-10T00:00:00.000+0000", but the record is empty when I queried
SELECT Id FROM <Table_name> where Scan_Date__c=TODAY
But I am retrieve the same data by using query
SELECT Id FROM <Table_name> where Scan_Date__c=YESTERDAY
BTW I am using JsForce with nodeJS.
I solved using DAY_ONLY()
I used the DAY_ONLY() with Scan_Date__c to just compare the date and ignore the time.
SELECT Id FROM <Table_name> where DAY_ONLY(Scan_Date__c)=TODAY
Reference
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_date_functions.htm#

ssis string variables value should be used in exequte sql task

I am trying to create a table. In the table name id is unique
(MARKET_id is the name of the table).
The id has leading zeros which needs to be preserved. So I declared id as a string variable.
Example: id=02161515. And in parameter mapping I mapped it as VARCHAR.
An error occurs when I'm using a sql statement CREATE TABLE MARKET_?;. It results in: CREATE TABLE MARKET_'02161515'; the quotes is unnecessary and throws an error found "'" in the sql statement.
Please help!
I guess you have columns added to your table, but are not posted?
One way to solve this would be to create two variables, one for the table name and one for the create table statement.
Example (for demonstration only):
First variable is TABLE_NAME and defined with the following expression for demonstration of dynamic naming:
"dmu.MY_TABLE_"+(DT_STR,30,1252)datepart("s",getdate()) + "( id int)"
Second variable is CREATE_TABLE_SQL and defined as follows:
"Create table "+ #[User::TABLE_NAME]
Next change the Settings of your Execute_SQL_Task:
Set SQLSourceType to Variable and SourceVariable to User::CREATE_TABLE_SQL
This will create the table in your database

sequelize: retrieve model of a manually created table

If i create tables with sequelize API (sequelize.define), it returns a model object (User in the following example) that i can use to do queries (User.find) and other kind of operations:
var User = sequelize.define('User', {/* ... */})
If i need to create a table in the db without that api, but i need to do it with a pure sql query, is there a way to retrieve the same model object for my manual table and use it like the others?
In sequelize.models i see all my tables but not the custom one.
You need to define a model using define with the tableName property set to your manually defined table.
The DB columns that you want to retrieve as a model's attributes must meet a number of criteria. Each should have a datatype that matches the column's type. They should have the same constraints (cascade, null etc) as the DB columns. The column name should either match what Sequelize automatically generates or be specified manually using field.
Since the table for this model has already been manually created, make sure that it is not sync'ed to the DB. To test that the model you have specified will work the manually specified table you should sync the model to a test database and compare the automatically generated SQL with the manually generated SQL You are using.
This answer is based on the documentation here.

Batch update by "update" query of cqlsh in Cassandra

I want to do batch update for all rows, using update query. I know there is BATCH query. But, I have to list all rows..
So, I want to do something like :
UPDATE test set value=0x31 where id in ( SELECT id from test );
Is there any way doing something like the above?
The idea is the same as SQL. select all rows & and insert them into "in" part.
The reason why I want to do this is that I added a new column to the existing column family, which created null data in the new created column.
And, this cause an error for retrieving data from Cassandra.
I think the examples shown here might help: http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/update_r.html?scroll=reference_ds_g4h_qzq_xj__description_unique_31
Update a column in several rows at once:
UPDATE users
SET state = 'TX'
WHERE user_uuid
IN (88b8fd18-b1ed-4e96-bf79-4280797cba80,
06a8913c-c0d6-477c-937d-6c1b69a95d43,
bc108776-7cb5-477f-917d-869c12dfffa8);

Adding Column Using Subsonic 3.0.0.5 Migration

I want to know that How to Insert New Columns to an existing database Table using Subsonic 3.0.0.5 MIGRATIONS.
Basically I want to alter an existing table in MS SqlServer database and add three more columns into it.
Please tell me How I will be able to do it
Regards,
Naveed Khan
Just change your object and the column will be added/updated whatever. So if you have an object called "Post" and add a property, it will be added as a column in the DB.
See this video...
http://subsonicproject.com/docs/Simple_Repo_5_Minute_Demo
It has to do with the conventions of SubSonic.
As the object is singular, it adds the plural to the table (or expects the table to be plural).
So it will expect an object called Order to map to a table called Orders.
There is only two solutions that I can see for you
1) Rename you table to the plural name.
2) Modify Subsonic code to remove the adding of the plural.

Resources