Comments (16)
I'll look into it.
from usql.
Formatting issues like this are because that's what the underlying database driver is returning, in this case raw bytes. That gets escaped/displayed as shown. To get better formatting, try casting/converting this field. Microsoft's documentation gives this:
CONVERT(CHAR(255), id_field) AS 'char'
This should get back to usql
as a string and then be displayed properly.
from usql.
Is there any way to customize (e.g. even a local build/patch/fork) usql to format it on the clientside without having to do the dance of modifying the query? I really like the look of usql, but if I get uniqueidentifiers formatted as binary blobs, that will severely limit the utility for my use-case at least. I'd have hoped that I could do stuff like select top 10 * from Foo
and do exploration of datashapes.
from usql.
@birkmose I've looked into the underlying type that should be returned by the driver, and it has a .String()
method, so it should have been picked up by the tblfmt
package properly. I'm trying to look into what the issue is, but for some reason Microsoft's SQL Server container images no longer work for me under Linux, even though I had been testing/using the same container image a week ago. I'll get to the bottom of this, as this is either an error in the underlying driver, or a minor logic issue with the tblfmt
package. I can't debug/test this, however, without having a database to test against.
from usql.
@birkmose I've been reading the SQL Server driver code, and it doesn't appear that it's ever allocating a UniqueIdentifier
type in a call to .Scan
. As such, this is likely an oversight or on purpose in the github.com/microsoft/go-mssqldb
code base. I won't be able to know until I can get the container image working again.
from usql.
This is the image i tested with on linux:
mcr.microsoft.com/azure-sql-edge:latest
from usql.
Breakage: microsoft/mssql-docker#868
from usql.
@birkmose After downgrading a kernel or two, I was able to get the container to run. The type being returned from the driver is indeed []uint8
. Currently, this is being displayed properly by usql
. The fix to this would be for the driver to correctly return a mssql.UniqueIdentifier
type. That would require a change to Microsoft's SQL Server Go driver.
from usql.
@birkmose I've dug deep into the SQL Server driver code, and it is not easy to fix this. From what I can tell, there's an internal call to parseRow
that is effectively dropping the type information. There's a convertAssign
func (that, from my reading, would not work, regardless, as nowhere in the codebase is a UniqueIdentifier
ever created). Separately, the actual convertAssign
doesn't but it doesn't seem to be in path that usql
, and, subsequently, tblfmt
call.
I could add a hack to usql
that adds formatting for []byte
of specific length 16, but even then this would be extremely broken, hackish, and really not what should be done.
The SQL Server driver just isn't up to the same kind of functionality/support that other database drivers are. Other drivers will convert to the "best type" when presented with a *interface{}
on a .Scan
call.
That said, the ultimate resolution to this would be to politely ask Microsoft to fix this in their code. I will implement the hack and push it to the tree, but the usql
codebase is being overhauled at the moment for a greater set of features, and thus I won't be able to cut a release any time soon. The hack I'll implement should be available in the next couple hours.
from usql.
@birkmose I think I have a non-hacky PR that I can get the MS repo to accept, which will require no changes to usql
or tblfmt
, but of course will require building from source until a new usql
release is cut (assuming the PR is accepted).
from usql.
@birkmose you can compile/use this from source yourself:
$ mkdir src
$ cd src
$ git clone https://github.com/kenshaw/go-mssqldb.git
$ git clone https://github.com/xo/usql.git
$ cd usql
$ go work init
$ go work use .
$ go work edit -replace github.com/microsoft/go-mssqldb=../go-mssqldb
$ go install
from usql.
Thanks @kenshaw!
The uniqueidentifier now works, but seems that master is broken - getting errors like:
error: sqlserver: sql: Scan error on column index 2, name "SomeColumnName": converting NULL to string is unsupported
(for a column nvarchar(255)
which is nullable).
from usql.
@birkmose Ok; and that wasn't happening before?
from usql.
Not from the v0.17.5
branch no. Just tested on that branch again, and works fine there :)
from usql.
@birkmose I pushed a new commit to fix this, without requiring any changes to the underlying driver. Please check it out and test it.
from usql.
Sorry for the late answer @kenshaw , got caught up in some other stuff. I can confirm that a simple git clone https://github.com/xo/usql.git; go install
works as expected - I know see uniqueidentifier
formatted as expected - thank you very much!
from usql.
Related Issues (20)
- [PATCH] A handy conninfo output HOT 2
- error csv upload with pgx driver (encode date column) HOT 14
- Executing SQL files without semicolon as end-of-statement HOT 9
- Prevent irrelevant output with CSV format
- Support log message for NOTIFY/LISTEN HOT 4
- No foreign keys displayed on sql server HOT 1
- Is terminal graphics in WezTerm under Windows supposed to work? HOT 1
- feature: connection aliases HOT 4
- '\timing on' not work in greenplum 6 HOT 5
- paste multi-line sql is a bit slow? HOT 2
- feature: add duckdb driver to base drivers HOT 1
- version 0.17.5 quit sliently on windows 7 HOT 2
- numbers displayed as 1.450817032e+ HOT 5
- I hope to add a feature similar to the grep filtering in Linux. HOT 3
- couchbase error: n1ql: Connection failed Post
- Feature request: implement the \bind meta-command HOT 6
- Using usql as a library (or subprocess) HOT 5
- Batch insert in \copy to DB destination HOT 1
- How to .usqlpass HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from usql.