I have a column in postgresql whose datatype is bytea.
the value is like : 10 10 20 20 10 10 20 10 10 20 10 10 20
I want to pull the data in snowflake now, but no idea what would be snowflake alternative
Any help will be highly appreciated
Since you don't know how this data is going to be used, then the best approach is to store it in a format that is efficient yet easy to transform at a later date. The closest equivalent data type to PostGres' bytea datatype is Snowflake's BINARY type, which allows for storage in hexadeximal format (hex), or as as printable ASCII characters (base64) (there is also a UTF-8 option but that probably isn't relevant here.
https://docs.snowflake.com/en/user-guide/binary-input-output.html
Thanks all, I got in touch with analytics team, that bytea data was of no use, so we have to skip those
Related
I've been having problems with a query that returns data between two date times, the query that I'm trying to fix is this one
pay.date BETWEEN '01/06/2020 00:28:46 a. m.' AND '01/06/2020 10:38:45 a. m.'
That query does not detect the a. m. part and if I have a payment at 10 am and 10 pm it will detect both payments as the t. t. part is not detected, I've been searching for a while now with no luck, thanks in advance :)
Do the filtering by an actual datetime type:
cast(replace(replace(pay.date, ' a. m.', 'am'), ' p. m.', 'pm') as datetime)
It might be better to use convert() so you can specify the proper format. If you can't supply the date literals in a readily convertible format then do a similar replace and cast on those too.
Use a literal format that is unambiguous and not dependent on runtime or connection settings. More info in Tibor's discussion.
In this case:
where pay.date between '20200601 00:28:46' and '20200601 10:38:45'
Notice that I assume June, not January - adjust as needed. Between is inclusive and be certain that you understand the limitations of the datatype for pay.date. If datetime, the values are accurate to 3ms. Verify that your data is consistent with your assumption about accuracy to seconds.
Below sql showing 57 hours, But,it's 44 hrs. How can i solve.
SELECT DATEDIFF(Hour,'2018-11-20 2:26:38.000','2018-11-22 11:00:29.367')
Use 24 hr format in both dates
SELECT DATEDIFF(Hour,'2018-11-20 14:26:38.000','2018-11-22 11:00:29.367')
Not prefixing the hours to be two digits looks like it could be the issue, making it unambiguously in the afternoon gives your result.
/*------------------------
SELECT DATEDIFF(Hour,'2018-11-20 14:26:38.000','2018-11-22 11:00:29.367')
------------------------*/
45
You're default Date Time format is probably 12 hour, and "2:…" is being treated as pm.
Using two digits for the hour should help.
/*------------------------
SELECT DATEDIFF(Hour,'2018-11-20 02:26:38.000','2018-11-22 11:00:29.367')
------------------------*/
57
(SQL Server has a lot of backward compatibility which may be triggered is the input is not precisely formatted, ISO Date/Time formats always use two digits for hours, minutes, and seconds.)
If you are using a client (rather than fixed code in a Stored Proc/Function/Trigger/…) parameterising your queries avoids this issue: pass data as Date-Time type directly without any need to convert into a string.
Having issues updating a Pervasive PSQL table using Pervasive Control Centre and wonder if anyone can point me in the right direction. I'm struggling to update a field in the table whose type is '254-VB Currency'.
Sample query:
Update TABLE set "remBal" = 100.00 where 'Posting' = 215288;
The value that ends up in the remBal field is 463673729135463.6288
Pervasive version is v10.30. Updating via e.g. VAccess control works fine. It's just Pervasive Control Centre that doesn't.
The VAccess control supports more data types than the standard PSQL engine does. The VB Currency data type is not one that's natively supported in PSQL.
According to MSDN, the Currency data type is defined as:
Currency variables are stored as 64-bit (8-byte) numbers in an integer
format, scaled by 10,000 to give a fixed-point number with 15 digits
to the left of the decimal point and 4 digits to the right. This
representation provides a range of -922,337,203,685,477.5808 to
922,337,203,685,477.5807.
What I would suggest, is enter 100.00 to the database using VAccess, then look at the value in Control Center. You can then use that value in your SQL statement. It's not pretty but it might work.
I am trying to query some data out of Home Bank using the data file it produces.
This is a transaction that appears in the file:
<ope date="734309" amount="-14.24" account="4" dst_account="0" paymode="0" flags="1" payee="239" category="2" wording="" info="" tags="" kxfer="0" />
I am interested in the date="734309". I've not seen this format before so don't know how to parse it.
The application is written in C if that is any help.
734309 / 365 = 2011.80548
So I guess it's something like "days since 1 January in the year 1". If you know the actual date that that number should represent, you can reconstruct the precise offset from there.
It's probably the result of the SQL TO_DAYS() function, which represents the number of days since the first day of 1 A.D. (I don't know whether TO_DAYS() is specific to MySQL or if it's a standard SQL function.)
I need to insert a year(eg:1988 ,1990 etc) in a database. When I used Date or Datetime
data type, it is showing errors. Which datatype should I use.
regular 4 byte INT is way too big, is a waste of space!
You don't say what database you're using, so I can't recommend a specific datatype. Everyone is saying "use integer", but most databases store integers as 4 bytes, which is way more than you need. You should use a two byte integer (smallint on SQL Server), which will conserve space.
If you need to store a year in the database, you would either want to use an Integer datatype (if you are dead set on only storing the year) or a DateTime datatype (which would involve storing a date that basically is 1/1/1990 00:00:00 in format).
Hey,you can Use year() datatype in MySQL
It is available in two-digit or four-digit format.
Note: Values allowed in four-digit format: 1901 to 2155. Values allowed in two-digit format: 70 to 69, representing years from 1970 to 2069
Storing a "Year" in MSSQL would ideally depend on what you are doing with it and what the meaning of that "year" would be to your application and database. That being said there are a few things to state here. There is no "DataType" for Year as of 2012 in MSSQL. I would lean toward using SMALLINT as it is only 2 bytes (saving you 2 of the 4 bytes that INT demands). Your limitation is that you can not have a year older than 32767 (as of SQL Server 2008R2). I really do not think SQL will be the database of choice ten thousand years from now let alone 32767. You may consider INT as the Year() function in MSSQL does convert the data type "DATE" to an INT. Like I said, it depends on where you are getting the data and where it is going, but SMALLINT should be just fine. INT would be overkill ... unless you have other reasons like the one I mentioned above or if the code requirements need it in INT form (e.g. integrating with existing application). Most likely SMALLINT should be just fine.
Just a year, nothing else ?
Why not use a simple integer ?
Use integer if all you need to store is the year. You can also use datetime if you think there will be date based calculations while querying this column
Storage may be only part of the issue. How will this value be used in a query?
Is it going to be compared with another date-time data types, or will all the associated rows also have numeric values?
How would you deal with a change to the requirements? How easily could you react to a request to replace the year with a smaller time slice? i.e. Now they want it broken down by quarters?
A numeric type can be easily used in a date time query by having a look-up table to join with containing things like the start and stop dates (1/1/X to 12/31/x), etc..
I don't think using an integer or any subtype of integer is a good choice. Sooner or later you will have to do other date like operations on it. Also in 2019 let's not worry too much about space. See what those saved 2 bytes costed us in 2000.
I suggest use a date of year + 0101 converted to a true date. Similarly if you need to store a month of a year store year + month + 01 as a true date.
If you have done that you will be able to properly do "date stuff" on it later on